package forms;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class formName extends ActionForm {
	private static final long serialVersionUID = 1L;
	private String first = null;
	private String middle = null;
	private String last = null;

	public String getFirst() {
		return first;
	}

	public String getLast() {
		return last;
	}

	public String getMiddle() {
		return middle;
	}

	public boolean isNumeric(String name) {
		try {
			Integer.parseInt(name);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		setFirst(null);
		setMiddle(null);
		setLast(null);
	}

	public void setFirst(String first) {
		this.first = first;
	}

	public void setLast(String last) {
		this.last = last;
	}

	public void setMiddle(String middle) {
		this.middle = middle;
	}

	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		if ((first == null) || (first.length() < 1) || (isNumeric(first))) {
			errors.add("firstMsgTag1", new ActionMessage("errors.required",
					"First Name"));
		}

		if ((last == null) || (last.length() < 1) || (isNumeric(last))) {
			errors.add("lastMsgTag1", new ActionMessage("errors.required",
					"Last Name"));
		}
		return errors;
	}
}